home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0092_Vesa Unit.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  3KB  |  138 lines

  1. {
  2. > Any chance you can post that uVesa Unit? Or maybe a routine to
  3. > set up a Vesa mode, and a Vesa plotPixel routine?
  4. }
  5.  
  6. UNIT uVesa;                                    { (c) 1993 by NEBULA-Software }
  7.      { Unterstützung des VESA-Standards      } { Olaf Bartelt & Oliver Carow }
  8.  
  9. INTERFACE                                      { Interface-Teil der Unit     }
  10.  
  11.  
  12. TYPE tVesa = OBJECT                            { Objekt für VESA             }
  13.                xmax, ymax : WORD;
  14.                page       : WORD;
  15.                switch_ptr : POINTER;
  16.  
  17.                CONSTRUCTOR init(modus : WORD);
  18.                PROCEDURE   putpixel(x, y : WORD; c : BYTE);  { Longint    }
  19.                FUNCTION    getpixel(x, y : LONGINT) : BYTE;  { wegen Berechn.}
  20.              END;
  21. VAR  vVesa : ^tVesa;
  22.  
  23.  
  24. CONST c640x400  = $100;                        { VESA-Modi                   }
  25.       c640x480  = $101;
  26.       c800x600  = $102;
  27.       c1024x768 = $103;
  28.  
  29. FUNCTION vesa_installed : BOOLEAN;
  30.  
  31.  
  32. IMPLEMENTATION                                 { Implementation-Teil d. Unit }
  33.  
  34. USES DOS, CRT;                                 { Units einbinden             }
  35.  
  36.  
  37. VAR regs   : REGISTERS;                        { benötigte Variablen         }
  38.  
  39.  
  40. FUNCTION vesa_installed : BOOLEAN;             { VESA-Treiber vorhanden?     }
  41. BEGIN
  42.   regs.AH := $4F; regs.AL := 0; INTR($10, regs);
  43.   vesa_installed := regs.AL = $4F;
  44. END;
  45.  
  46.  
  47. CONSTRUCTOR tVesa.init(modus : WORD);
  48. VAR mib  : ARRAY[0..255] OF BYTE;
  49.     s, o : WORD;
  50. BEGIN
  51.   IF vesa_installed = FALSE THEN
  52.   BEGIN
  53.     WRITELN(#7, 'Kein VESA-Treiber installiert! / No VESA-driver installed!');
  54.     HALT(1);
  55.   END;
  56.  
  57.   regs.AX := $4F02; regs.BX := modus; INTR($10, regs);
  58.   regs.AX := $4F01; regs.DI := SEG(mib); regs.ES := OFS(mib); INTR($10, regs);
  59.  
  60.   s := mib[$0C] * 256 + mib[$0D]; o := mib[$0E] * 256 + mib[$0F];
  61.   switch_ptr := PTR(s, o);
  62.  
  63.   CASE modus OF
  64.     c640x400 : BEGIN xmax := 640; ymax := 400; END;
  65.     c640x480 : BEGIN xmax := 640; ymax := 480; END;
  66.     c800x600 : BEGIN xmax := 800; ymax := 600; END;
  67.     c1024x768: BEGIN xmax := 1024; ymax := 768; END;
  68.   END;
  69.  
  70.   page := 0;
  71.   ASM
  72.     MOV AX, 4F05h
  73.     MOV DX, page
  74.     INT 10h
  75.   END;
  76. END;
  77.  
  78.  
  79. PROCEDURE   tVesa.putpixel(x, y : WORD; c : BYTE);
  80. VAR bank   : WORD;
  81.     offs   : LONGINT;
  82. BEGIN
  83.   offs := LONGINT(y)*640 + x;     { SHL 9+SHL 7 ist auch nicht schneller!! }
  84.   bank := offs SHR 16;
  85.   offs := offs - (bank SHL 16);   { MOD 65536 ist langsamer!! }
  86.  
  87.   IF bank <> page THEN
  88.   BEGIN
  89.     page := bank;
  90.     ASM
  91.       MOV AX, 4F05h
  92.       MOV DX, bank
  93.       INT 10h
  94.     END;
  95.   END;
  96.  
  97.   ASM
  98.     MOV AX, 0A000h
  99.     MOV ES, AX
  100.     MOV DI, WORD(offs)
  101.     MOV AL, c
  102.     MOV ES:[DI], AL
  103.   END;
  104. END;
  105.  
  106.  
  107. FUNCTION    tVesa.getpixel(x, y : LONGINT) : BYTE;
  108. VAR bank   : WORD;
  109.     offset : LONGINT;
  110. BEGIN
  111.   offset := y SHL 9+y SHL 7+x;
  112.   bank := offset SHR 16;
  113.   offset := offset - (bank SHL 16);
  114.  
  115.   IF bank <> page THEN
  116.   BEGIN
  117.     page := bank;
  118.     ASM
  119.       MOV AX, 4F05h
  120.       MOV DX, bank
  121.       INT 10h
  122.     END;
  123.   END;
  124.  
  125.   getpixel := MEM[$A000:offset];
  126. END;
  127.  
  128.  
  129. BEGIN
  130.   NEW(vVesa);
  131. END.
  132.  
  133. {
  134. That routine could be faster if one implemented a bank switching routine by
  135. doing a far call to the vesa bios (the address can be received by a simple
  136. call, I just hadn't had time yet to implement it - if you should do it,
  137. *please* post the modified routine for me - thanx!)
  138. }